<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                template="/templates/template.xhtml">

    <ui:define name="title">模板项配置</ui:define>
    <ui:define name="content">
        <h:form id="optionForm">
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="right">
                        <p:commandButton value="保存" icon="fa fa-save"
                                         actionListener="#{activityItemListBean.onSave}"
                                         update="@form"/>
                        <p:button value="返回" icon="fa fa-reply-all" href="/views/templateConf/activityConf/activitylist.xhtml"/>
                    </f:facet>
                </p:toolbar>
            </div>

            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">

                        <div class="card">
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">

                                <p:outputLabel for="apiName" value="模板名"/>
                                <p:inputText id="apiName" value="#{activityItemListBean.$.apiName}"/>

                                <p:outputLabel for="third" value="甲方名"/>
                                <p:selectOneMenu id="third" value="#{activityItemListBean.$.thirdId}">
                                    <f:selectItem itemLabel="非API" itemValue="-1" noSelectionOption="true"/>
                                    <f:selectItems value="#{activityItemListBean.thirdList}" var="model"
                                                   itemLabel="#{model.thirdName}" itemValue="#{model.thirdId}"/>
                                </p:selectOneMenu>
                            </p:panelGrid>
                        </div>

                        <!-- 列表 -->
                        <div class="cad">
                            <p:growl id="msgs" showDetail="true"/>

                            <p:dataTable id="itemListDataTable"
                                         widgetVar="dataTable"
                                         style="width: 100%"
                                         var="item"
                                         value="#{activityItemListBean.itemList}"
                                         scrollable="true"
                                         scrollWidth="100%"
                                         editable="true"
                            >

                                <p:ajax event="rowEdit" listener="#{activityItemListBean.onRowEdit}" update=":optionForm:msgs"/>
                                <p:ajax event="rowEditCancel" listener="#{activityItemListBean.onRowCancel}" update="itemListDataTable"/>

                                <p:column headerText="操作">
                                    <p:splitButton icon="#">
                                        <p:menuitem value="编辑二级项" icon="ui-icon-arrowrefresh-1-w"
                                                    actionListener="#{activityItemListBean.onEditSecond(item.id)}"
                                                    update="@form" oncomplete="PF('itemOptionDialog').show()">
                                        </p:menuitem>
                                        <p:menuitem value="编辑校验规则" icon="ui-icon-arrowrefresh-1-w"
                                                    actionListener="#{activityItemListBean.onValiRule(item.id)}"
                                                    update="@form" oncomplete="PF('valiRuleDialog').show()">
                                        </p:menuitem>
                                    </p:splitButton>
                                </p:column>

                                <p:column headerText="一级项ID">
                                    <h:outputText value="#{item.id}" />
                                </p:column>

                                <p:column headerText="一级项名" width="15%">
                                    <p:cellEditor>
                                        <f:facet name="output">
                                            <p:selectOneMenu value="#{item.itemBasisId}" disabled="true">
                                                <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true" />
                                                <f:selectItems value="#{activityItemListBean.allModelItemBasisList}" var="model"
                                                               itemLabel="#{model.title}" itemValue="#{model.id}"/>
                                            </p:selectOneMenu>
                                        </f:facet>
                                        <f:facet name="input">
                                            <p:selectOneMenu value="#{item.itemBasisId}" filter="true" filterMatchMode="startsWith">
                                                <f:selectItems value="#{activityItemListBean.allModelItemBasisList}" var="model"
                                                               itemLabel="#{model.title}" itemValue="#{model.id}"/>
                                            </p:selectOneMenu>
                                        </f:facet>
                                    </p:cellEditor>
                                </p:column>

                                <p:column headerText="所属页面栏目">
                                    <p:cellEditor>
                                        <f:facet name="output">
                                            <p:selectOneMenu value="#{item.pageId}" disabled="true">
                                                <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                                <f:selectItems value="#{activityItemListBean.modelPageList}" var="model"
                                                               itemLabel="#{model.pageName}" itemValue="#{model.id}"/>
                                            </p:selectOneMenu>
                                        </f:facet>
                                        <f:facet name="input">
                                            <p:selectOneMenu value="#{item.pageId}">
                                                <f:selectItems value="#{activityItemListBean.modelPageList}" var="model"
                                                               itemLabel="#{model.pageName}" itemValue="#{model.id}"/>
                                            </p:selectOneMenu>
                                        </f:facet>
                                    </p:cellEditor>
                                </p:column>

                                <p:column headerText="父项">
                                    <p:cellEditor>
                                        <f:facet name="output">
                                            <p:selectOneMenu value="#{item.parentItemId}" disabled="true">
                                                <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                                <f:selectItems value="#{activityItemListBean.apiModelItemBasisList}" var="model"
                                                               itemLabel="#{model.title}" itemValue="#{model.id}"/>
                                            </p:selectOneMenu>
                                        </f:facet>
                                        <f:facet name="input">
                                            <p:selectOneMenu value="#{item.parentItemId}">
                                                <f:selectItem itemLabel="- 请选择 -" itemValue="0" noSelectionOption="true"/>
                                                <f:selectItems value="#{activityItemListBean.apiModelItemBasisList}" var="model"
                                                               itemLabel="#{model.title}" itemValue="#{model.id}"/>
                                            </p:selectOneMenu>
                                        </f:facet>
                                    </p:cellEditor>
                                </p:column>

                                <p:column headerText="是否必填" width="7%">
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{item.necessary==1?'是':'否'}"/></f:facet>
                                        <f:facet name="input">
                                            <p:selectOneMenu value="#{item.necessary}">
                                                <f:selectItem itemLabel="是" itemValue="1"/>
                                                <f:selectItem itemLabel="否" itemValue="0"/>
                                            </p:selectOneMenu>
                                        </f:facet>
                                    </p:cellEditor>
                                </p:column>

                                <p:column headerText="排序号" width="7%">
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{item.sort}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{item.sort}"  style="width:100%" label="排序号"/></f:facet>
                                    </p:cellEditor>
                                </p:column>

                                <p:column headerText="合作方对应项">
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{item.partnerKey}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{item.partnerKey}" style="width:100%" label="合作方对应项"/></f:facet>
                                    </p:cellEditor>
                                </p:column>

                                <p:column headerText="默认提示">
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{item.placeholder}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{item.placeholder}" style="width:100%" label="默认提示"/></f:facet>
                                    </p:cellEditor>
                                </p:column>

                                <p:column headerText="默认值">
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{item.defaultValue}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{item.defaultValue}" style="width:100%" label="默认值"/></f:facet>
                                    </p:cellEditor>
                                </p:column>

                                <p:column style="width:32px">
                                    <p:rowEditor/>
                                </p:column>
                            </p:dataTable>
                        </div>
                        <!-- 列表 -->
                    </div>

                    <div class="ui-g-12">
                        <p:commandButton value="新增行" styleClass="ui-priority-primary" process="@this"
                                         update=":optionForm:msgs"
                                         action="#{activityItemListBean.onAddNew(activityItemListBean.$.id)}"
                                         oncomplete="PF('dataTable').addRow();"/>
                    </div>
                </div>
            </div>
            <!-- 弹窗 -->
            <ui:include src="itemOptionList-dialog.xhtml"/>
            <ui:include src="valiRuleList-dialog.xhtml"/>
        </h:form>
    </ui:define>
</ui:composition>